﻿//-----------------------------------------------------------------------
// <copyright file="Program.cs" company="CodePlex">
//     Copyright (c) Doug Holland, CodePlex. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace CodePlex.DesignPatterns
{
    using System;
    using System.Diagnostics;

    /// <summary>
    /// Defines the program entry point for the Singleton sample.
    /// </summary>
    internal static class Program
    {
        #region private static void Main(string[] args)

        /// <summary>
        /// Defines the program entry point.
        /// </summary>
        /// <param name="args">A <see cref="T:System.String"/> array containing any command line arguments specified at runtime.</param>
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            // create two references to the same unique Singleton instance.
            Singleton s1 = Singleton.UniqueInstance;
            Singleton s2 = Singleton.UniqueInstance;

            // verify that the two references do indeed refer to the same object instance.
            Debug.Assert(object.ReferenceEquals(s1, s2), "error: instances of the Singleton class do not refer to a unique instance as expected.");

            Console.ReadLine();
        }

        #endregion

        #region private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)

        /// <summary>
        /// Handles the <see cref="M:System.AppDomain.UnhandledException"/> event of the current <see cref="T:System.AppDomain"/>.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.UnhandledExceptionEventArgs"/> instance containing the event data.</param>
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception;

            if (ex != null)
            {
                // TODO: publish exception using the Enterprise Library or alternatively the CodePlex.Diagnostics framework.
            }

            throw new NotImplementedException();
        }

        #endregion
    }
}
